package com.andyage.admin.action;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.andyage.admin.bean.AdLogBean;
import com.andyage.admin.service.IAdLogService;
import com.andyage.util.DateUtil;
@Controller
@RequestMapping("/admin")
public class AdLogAction {
	@Resource
	private IAdLogService iadlogService;
	@RequestMapping("/queryAdLogInfo")
	public void queryAdLogInfo(AdLogBean adlog,HttpServletResponse response,HttpServletRequest request) {
		String startDate = request.getParameter("sstartDate");
		String endDate = request.getParameter("sendDate");
		if(startDate!=null&&endDate!=null){
			adlog.setStartDate(DateUtil.getDate(startDate,"yyyy-MM-dd"));
			adlog.setEndDate(DateUtil.getDate(endDate,"yyyy-MM-dd"));
		}
		try {
			String json  = iadlogService.queryAdLogInfo(adlog);
			response.setContentType("text/html;charset=UTF-8");
			response.getWriter().print(json);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@RequestMapping("/deleteAdLogByLogId")
	public void deleteAdLogByLogId(HttpServletResponse response,HttpServletRequest request) {
		String logIds = request.getParameter("logId");
		String[] logId = logIds.split(",");
		List<String> list = new ArrayList<>();
		for(int i=0;i<logId.length;i++){
			list.add(logId[i]);
		}
		try {
			String json = iadlogService.deleteAdLogByLogId(list);
			response.setContentType("text/html;charset=UTF-8");
			response.getWriter().print(json);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
